GdPicture.NET.14
GdPicture14 Namespace / GdPicturePDF Class / MergeDocuments Method / MergeDocuments(GdPicturePDF[],PdfDocumentMergingOptions) Method
An array of the GdPicturePDF objects keeping the PDF documents you want to merge.

You need to load PDF documents within the objects, as it is shown in the example below.

A member of the PdfDocumentMergingOptions enumeration. Specifies required merging options.
Example





In This Topic
MergeDocuments(GdPicturePDF[],PdfDocumentMergingOptions) Method
In This Topic
Merges several PDF documents loaded within the array of the GdPicturePDF objects. The resulting PDF document is created and stored within the new GdPicturePDF object as well. Using this method you can additionally select preferred merging options.

If the first PDF document in the list (stored in the first GdPicturePDF object in the input parameter) is PDF/A compliant, the resulting document will also be PDF/A compliant. The conformance level and version of the merged document will be PDF/A-1b regardless of the original conformance of the first source document.

Just to inform you, that the toolkit offers the adaptive file caching mechanism to significantly reduce memory usage while merging large documents. The feature is available in both 32-bit and 64-bit mode by default.

Syntax
'Declaration
 
Public Overloads Function MergeDocuments( _
   ByVal SrcDoc() As GdPicturePDF, _
   ByVal Options As PdfDocumentMergingOptions _
) As GdPicturePDF
public function MergeDocuments( 
    SrcDoc: GdPicturePDFarray of;
    Options: PdfDocumentMergingOptions
): GdPicturePDF; 
public function MergeDocuments( 
   SrcDoc : GdPicturePDF[],
   Options : PdfDocumentMergingOptions
) : GdPicturePDF;

Parameters

SrcDoc
An array of the GdPicturePDF objects keeping the PDF documents you want to merge.

You need to load PDF documents within the objects, as it is shown in the example below.

Options
A member of the PdfDocumentMergingOptions enumeration. Specifies required merging options.

Return Value

A newly created GdPicturePDF object which keeps the merged PDF document. The GetStat method can be subsequently used to determine if this method has been successful.

All pages of the source documents are cloned one by one to the destination document in that order how they are stored in the input parameter.

Remarks
This method is only allowed for use with non-encrypted documents.

It is recommend to use the GetStat method to identify the specific reason for the method's failure, if any.

The last page in each of used documents and also in the resulting document is set as the current document's page after the merging process.

This method requires the Document Editor component to run.

Example
How to merge 3 PDF documents from an array of GdPicturePDF objects into a new GdPicturePDF object. In this example all attachments are excluded from the merging process.
Dim arPDF As GdPicturePDF() = New GdPicturePDF(2) {}
arPDF(0) = New GdPicturePDF()
arPDF(1) = New GdPicturePDF()
arPDF(2) = New GdPicturePDF()
If (arPDF(0).LoadFromFile("test1.pdf", False) = GdPictureStatus.OK) AndAlso
    (arPDF(1).LoadFromFile("test2.pdf", False) = GdPictureStatus.OK) AndAlso
    (arPDF(2).LoadFromFile("test3.pdf", False) = GdPictureStatus.OK) Then
    Dim dstPDF As GdPicturePDF = arPDF(0).MergeDocuments(arPDF, PdfDocumentMergingOptions.ExcludeAttachments)
    'You can use also arPDF[1] or arPDF[2] object to call the MergeDocuments method.
    Dim status As GdPictureStatus = arPDF(0).GetStat()
    If status = GdPictureStatus.OK Then
        MessageBox.Show("All documents have been successfully merged.", "Example: MergeDocuments")
        If dstPDF.SaveToFile("test_merged.pdf") = GdPictureStatus.OK Then
            MessageBox.Show("Merged document has been successfully saved.", "Example: MergeDocuments")
            dstPDF.CloseDocument()
        End If
    Else
        MessageBox.Show("The MergeDocuments() method has failed with the status: " + status.ToString(), "Example: MergeDocuments")
    End If
    dstPDF.Dispose()
    arPDF(2).CloseDocument()
    arPDF(1).CloseDocument()
    arPDF(0).CloseDocument()
Else
    MessageBox.Show("Loading of the source documents has failed.", "Example: MergeDocuments")
End If
arPDF(2).Dispose()
arPDF(1).Dispose()
arPDF(0).Dispose()
GdPicturePDF[] arPDF = new GdPicturePDF[3];
arPDF[0] = new GdPicturePDF();
arPDF[1] = new GdPicturePDF();
arPDF[2] = new GdPicturePDF();
if ((arPDF[0].LoadFromFile("test1.pdf", false) == GdPictureStatus.OK) &&
    (arPDF[1].LoadFromFile("test2.pdf", false) == GdPictureStatus.OK) &&
    (arPDF[2].LoadFromFile("test3.pdf", false) == GdPictureStatus.OK))
{
    GdPicturePDF dstPDF = arPDF[0].MergeDocuments(arPDF, PdfDocumentMergingOptions.ExcludeAttachments);
    //You can use also arPDF[1] or arPDF[2] object to call the MergeDocuments method.
    GdPictureStatus status = arPDF[0].GetStat();
    if (status == GdPictureStatus.OK)
    {
        MessageBox.Show("All documents have been successfully merged.", "Example: MergeDocuments");
        if (dstPDF.SaveToFile("test_merged.pdf") == GdPictureStatus.OK)
        {
            MessageBox.Show("Merged document has been successfully saved.", "Example: MergeDocuments");
            dstPDF.CloseDocument();
        }
    }
    else
    {
        MessageBox.Show("The MergeDocuments() method has failed with the status: " + status.ToString(), "Example: MergeDocuments");
    }
    dstPDF.Dispose();
    arPDF[2].CloseDocument();
    arPDF[1].CloseDocument();
    arPDF[0].CloseDocument();
}
else
{
    MessageBox.Show("Loading of the source documents has failed.", "Example: MergeDocuments");
}
arPDF[2].Dispose();
arPDF[1].Dispose();
arPDF[0].Dispose();
See Also